package com.ujiuye.servlet;

import com.ujiuye.entity.User1;
import com.ujiuye.service.User1Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

@WebServlet("/s2")
public class RegisServlet extends HttpServlet {
    User1Service service = new User1Service();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String name = req.getParameter("name");
        String sex = req.getParameter("sex");
        String sdesc = req.getParameter("sdesc");
        String[] hobbies = req.getParameterValues("hobby");
        User1 user1 = new User1();
        user1.setUsername(username);
        user1.setPassword(password);
        user1.setSex(sex);
        user1.setName(name);
        user1.setSdesc(sdesc);
        user1.setHobby(Arrays.toString(hobbies));
        int regist = service.regist(user1);
        if(regist>0){
            req.getRequestDispatcher("/html/login.html").forward(req,resp);
        }else{
            System.out.println("注册失败");
        }
    }
}
